<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>远强记事本</title>
    <style>
      .box {
        width: 300px;
        min-height: 10px;
        margin: 20px auto;
        background-color: white;
        padding-top: 5px;
        display: flex;
        flex-direction: column;
        flex: 1;
      }
      h1 {
        color: red;
        text-align: center;
        padding: 0;
        margin: 0 auto;
      }
      body {
        background-color: #f1f1f1;
      }

      .body-1 {
        height: 40px;
        width: 280px;
        margin: 10px auto;
        border: solid 3px red;
        border-radius: 10px;
        display: flex;
      }
      .body-1-right {
        width: 75px;
        height: 100%;
        background-color: red;
        font-size: 13px;
        text-align: center;
        color: white;
      }
      input {
        flex: 1;
        border-style: none;
        border-radius: 10px;
        outline: none;
        text-indent: 15px;
      }
      .list {
        width: 280px;
        height: 45px;
        border-bottom: solid 3px grey;
        padding: 3px 0px 0px 3px;
        line-height: 45px;
        display: flex;
        justify-content: space-between;
      }
      button.del {
        visibility: hidden;
      }
      .list:hover .del {
        visibility: visible;
      }
      ul {
        padding-left: 5px;
      }
      li {
        list-style: none;
      }
      .foot {
        justify-content: space-between;
        display: flex;
        padding: 0 10px 0 5px;
      }
      button {
        background-color: transparent;
        border-style: none;
        cursor: pointer;
      }
      .body-1-right button {
        padding: 0;
        margin: 10px 0 0 0;
      }
    </style>
  </head>
  <body>
    <h1>远强记事本</h1>
    <div class="box" id="app">
      <div class="body">
        <div class="body-1">
          <input
            @keyup.enter="ad"
            v-model.trim="temp"
            type="text"
            placeholder="请输入"
          />
          <div class="body-1-right">
            <button @click="ad">添加任务</button>
          </div>
        </div>
        <ul>
          <li>
            <div class="list" v-for="(item,index) in list" :key="item.id">
              <span>{{index+1}}.{{item.name}}</span>
              <button class="del" @click="del(item.id)">X</button>
            </div>
          </li>
        </ul>
        <div class="foot" v-show="list.length>0">
          <span>合计：<strong>{{list.length}}</strong></span>
          <button @click="clear">清空</button>
        </div>
      </div>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          list: [
            { id: 1, name: "形势与政策考试" },
            { id: 2, name: "王者荣耀打上钻石" },
            { id: 3, name: "刷哔哩哔哩" },
            { id: 4, name: "打羽毛球" },
          ],
          temp: "",
        },
        methods: {
          del(id) {
            this.list = this.list.filter((item) => item.id !== id);
          },
          ad() {
            if (this.temp.trim() === "") {
              alert("请输入内容");
              return;
            }
            this.list.push({
              id: Date.now(),
              name: this.temp,
            });
            this.temp = "";
          },
          clear() {
            this.list = [];
          },
        },
      });
    </script>
  </body>
</html>
